IMAT1604: Visual Web Development

Custom Classes

In order to retrieve records from the database, a class is needed to store the record in memory so that it can be manipulated in code. Thus for every table in the database there needs to be a class with the same fields as the table. In this case the Class is called Wine, and is used to store records retrieved from the Wines table. Note table names are plural, as they contains many records, and a class name is singular.

To add a new class first add an ASP.NET folder called App_Code. Then right click on the folder and select Add Class. Once added, ALWAYS REMEMBER TO select the file, goto the properties window and change Build Action to Complie otherwise the class will not be built, and you will not be able to use it in the code.

Although records contain fields or attributes, classes need to contain public properties. Properties can be added by typing prop, and then pressing the tab key. The properties type then needs to be changed as does the properties name.

Classes can contain fields, these are the same as properties except that they are private and not public. Only public properties can be accessed by other classes.

C# Custom Class - Wine

Comments above the start of a class or method should be Block comments which in C# can be obtained by entering three forward slashes. Single line comments can be added inside a class and these are entered using a double slash.

Block comments can be automatically extracted to create documentation for the code.